import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/home/Home.vue'
import Detail from '../views/detail/Detail.vue'
import Category from '../views/category/Category.vue'
import Shopcart from '../views/shopcart/Shopcart.vue'
import Profile from '../views/profile/Profile.vue'

const routes = [
  {
    path: '/',
    name: 'default',
    component: Home,
    meta: {
      title: 'Blizzard'
    }
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      title: 'Blizzard'
    }
  },
  {
    path: '/detail',
    name: 'Detail',
    component: Detail,
    meta: {
      title: '详情'
    }
  },
  {
    path: '/category',
    name: 'Category',
    component: Category,
    meta: {
      title: '分类'
    }
  },
  {
    path: '/shopcart',
    name: 'Shopcart',
    component: Shopcart,
    meta: {
      title: '购物车'
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: Profile,
    meta: {
      title: '个人中心'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta ? to.meta.title : 'Blizzard'
  next()
})

export default router
